package com.whale.kernel.utils;

import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;

public class FileUtils {

	public static String readClassPathResource(String resourcePath) {
		InputStream input = FileUtils.class.getClassLoader().getResourceAsStream(resourcePath);
		if (input==null) {
			throw new IllegalArgumentException("В classPath не найден ресурс: " + resourcePath);
		}
		String result;
		try {
			result = IOUtils.toString(input);
		} catch (IOException e) {
			throw new IllegalStateException(e.getMessage(), e);
		} finally {
			try {
				input.close();
			} catch (IOException e) {
				throw new IllegalStateException(e.getMessage(), e);
			}
		}
		return result;
	}
}
